#include "../include/Employee.h"
//extern int Manager::manager_cnt = 0;
//extern int Engineer::engineer_cnt = 0;
//extern int Salesman::salesman_cnt = 0;
//extern int Desginer::desginer_cnt = 0;


string Employee::getName()
{
    return this->name;
}

void Employee::create()
{

    string name_;
    string sex_;
    int age_;
    int basic_salary_;
    int id_;
    int job_salary_;
    int subsidy_;
    int insurance_;

    cout<<"Please input name"<<endl;
    cin>>name_;
    cout<<"Please input sex"<<endl;
    cin>>sex_;
    cout<<"Please input age"<<endl;
    cin>>age_;
    cout<<"Please input basic salary"<<endl;
    cin>>basic_salary_;
    cout<<"Please input worker id"<<endl;
    cin>>id_;
    cout<<"Please input subsidy"<<endl;
    cin>>subsidy_;
    cout<<"Please input insurance"<<endl;
    cin>>insurance_;

    this->age = age_;
    this->name = name_;
    this->basic_salary = basic_salary_;
    this->id = id_;
    this->insurance = insurance_;
    this->sex = sex_;
    this->subsidy = subsidy_;

    system("clear");
    Mat complish = imread("/home/zcf/公共的/keshe/images/complish.png");
    //resize(complish,complish,Size(1280,720));
    imshow("print",complish);
    waitKey(1000);
}

void Employee::write(cv::FileStorage& fs) const
{
    
    fs<<"{"<<"name"<<name<<"sex"<<sex<<"age"<<age<<"basic_salary"<<basic_salary<<"id"<<id<<"job_salary"<<job_salary<<"subsidy"<<subsidy<<"insurance"<<insurance<<"face"<<face<<"}";

}
void Employee::read(const cv::FileNode& node)
{
    name = (string)node["name"];
    sex = (string)node["sex"];
    age = (int)node["age"];
    basic_salary = (int)node["basic_salary"];
    id = (int)node["id"];
    job_salary = (int)node["job_salary"];
    subsidy = (int)node["subsidy"];
    insurance = (int)node["insurance"];
    face = (string)node["face"];
}



void Manager::print()
{
    //cout<<Manager::manager_cnt<<endl<<face<<endl;
    cv::Mat face_img = imread(face);
    if(face_img.empty())
    {
        cout<<"image error"<<endl;
        cv::waitKey(0);
    }
    cv::Scalar color = cv::Scalar(0,0,255);
    cv::resize(face_img,face_img,cv::Size(1200,1200));
    cv::putText(face_img,"job: Manager",cv::Point(100,200),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"Name: "+name,cv::Point(100,300),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"age: "+to_string(age),cv::Point(900,400),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"sex: "+sex,cv::Point(900,500),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"basic: "+to_string(basic_salary),cv::Point(100,700),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"addition: "+to_string(job_salary),cv::Point(100,800),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"ID: "+to_string(id),cv::Point(100,400),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"subsidy: "+to_string(subsidy),cv::Point(100,500),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"insure: "+to_string(insurance),cv::Point(100,600),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::imshow("print",face_img);
}

void Manager::countSalary(int& total ,int& avg)
{
    int sum = job_salary + basic_salary + subsidy;
    if(sum > 5000)
        sum *= 0.8;
    else if(sum > 3000)
        sum *= 0.9;
    sum -= insurance;
    sum += 1000;
    avg = (job_salary+basic_salary+subsidy)/3;
    total = sum;
}

void Engineer::print()
{
    cv::Mat face_img = imread(face);
    cv::Scalar color = cv::Scalar(0,0,255);
    cv::resize(face_img,face_img,cv::Size(1200,1200));
    cv::putText(face_img,"job: Engineer",cv::Point(100,200),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"Name: "+name,cv::Point(100,300),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"age: "+to_string(age),cv::Point(900,400),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"sex: "+sex,cv::Point(900,500),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"basic: "+to_string(basic_salary),cv::Point(100,700),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"addition: "+to_string(job_salary),cv::Point(100,800),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"ID: "+to_string(id),cv::Point(100,400),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"subsidy: "+to_string(subsidy),cv::Point(100,500),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"insure: "+to_string(insurance),cv::Point(100,600),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::imshow("print",face_img);
}

void Engineer::countSalary(int& total ,int& avg)
{
    int sum = job_salary + basic_salary + subsidy;
    if(sum > 5000)
        sum *= 0.9;
    else if(sum > 3000)
        sum *= 0.95;
    sum -= insurance;
    avg = (job_salary+basic_salary+subsidy)/3;
    total = sum;
}


void Salesman::print()
{
    cv::Mat face_img = imread(face);
    cv::Scalar color = cv::Scalar(0,0,255);
    cv::resize(face_img,face_img,cv::Size(1200,1200));
    cv::putText(face_img,"job: Salesman",cv::Point(100,200),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"Name: "+name,cv::Point(100,300),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"age: "+to_string(age),cv::Point(900,400),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"sex: "+sex,cv::Point(900,500),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"basic: "+to_string(basic_salary),cv::Point(100,700),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"addition: "+to_string(job_salary),cv::Point(100,800),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"ID: "+to_string(id),cv::Point(100,400),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"subsidy: "+to_string(subsidy),cv::Point(100,500),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"insure: "+to_string(insurance),cv::Point(100,600),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::imshow("print",face_img);
}

void Salesman::countSalary(int& total ,int& avg)
{
    int sum = job_salary + basic_salary + subsidy;
    if(sum > 5000)
        sum *= 0.7;
    else if(sum > 3000)
        sum *= 0.8;
    sum -= insurance;
    avg = (job_salary+basic_salary+subsidy)/3;
    total = sum;
}


void Desginer::print()
{
    cv::Mat face_img = imread(face);
    cv::Scalar color = cv::Scalar(0,0,255);
    cv::resize(face_img,face_img,cv::Size(1200,1200));
    cv::putText(face_img,"job: Desginer",cv::Point(100,200),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"Name: "+name,cv::Point(100,300),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"age: "+to_string(age),cv::Point(900,400),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"sex: "+sex,cv::Point(900,500),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"basic: "+to_string(basic_salary),cv::Point(100,700),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"addition: "+to_string(job_salary),cv::Point(100,800),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"ID: "+to_string(id),cv::Point(100,400),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"subsidy: "+to_string(subsidy),cv::Point(100,500),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::putText(face_img,"insure: "+to_string(insurance),cv::Point(100,600),FONT_HERSHEY_COMPLEX_SMALL,2,color,2);
    cv::imshow("print",face_img);
}

void Desginer::countSalary(int& total ,int& avg)
{
    int sum = job_salary + basic_salary + subsidy;
    if(sum > 5000)
        sum *= 0.75;
    else if(sum > 3000)
        sum *= 0.85;
    sum -= insurance;
    sum += 500;
    avg = (job_salary+basic_salary+subsidy)/3;
    total = sum;
}

ostream& operator<<(ostream& os,Employee& epl)
{
    int avg=0,total=0;
    epl.countSalary(total,avg);
    os<<"------------------------------------------------------"
    <<"------------------------------------------------------"<<endl;
    os<<"|name: "<<setw(10)<<epl.name<<"   |sex: "<<setw(10)<<epl.sex<<"   |id: "<<setw(10)<<epl.id
        <<"   |total salary: "<<setw(10)<<total<<"   |";
    return os;
}


